package es.cazadoresmadridejos.beans.manager.event.impl;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import es.cazadoresmadridejos.beans.dao.event.EventDao;
import es.cazadoresmadridejos.beans.manager.event.EventManager;
import es.cazadoresmadridejos.common.bean.dao.Dao;
import es.cazadoresmadridejos.common.bean.manager.impl.ManagerImpl;
import es.cazadoresmadridejos.model.Event;
import es.cazadoresmadridejos.model.Event.EventType;

@Service
public class EventManagerImpl extends ManagerImpl<Event> 
	implements EventManager{
	
	private SimpleDateFormat sdf = new SimpleDateFormat("d_M_yyyy");
	
	@Autowired 
	public void setDao(@Qualifier("eventDao")
	Dao<Event> dao) {
		this.dao = dao;
	}

	@Override
	public void deleteByExample(Event event) {
		((EventDao)dao).deleteByExample(event);
	}

	@Override
	public List<String> findAllByType(EventType type, Long idReason) {
		List<String> result = new ArrayList<String>();
		List<Event> events =  ((EventDao)dao).findAllByType(type, idReason);
		
		for (Event event : events) {
			result.add(sdf.format(event.getDate()));
		}
		
		return result;
	}

}
